package com.bianyuanren.web.controller.app;

import java.util.List;

import com.bianyuanren.v4.pojo.dynamicreport.PpDynamicReport;
import com.bianyuanren.v4.service.dynamicreport.IPpDynamicReportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.bianyuanren.common.annotation.Log;
import com.bianyuanren.common.enums.BusinessType;
import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.common.utils.poi.ExcelUtil;
import com.bianyuanren.common.core.page.TableDataInfo;

/**
 * 举报动态Controller
 * 
 * @author bianyuanren
 * @date 2020-05-14
 */
@Controller
@RequestMapping("/app/dynamicreport")
public class AppDynamicReportController extends BaseController
{
    private String prefix = "app/dynamicreport";

    @Autowired
    private IPpDynamicReportService ppDynamicReportService;

    @RequiresPermissions("system:report:view")
    @GetMapping()
    public String report()
    {
        return prefix + "/report";
    }

    /**
     * 查询举报动态列表
     */
   /* @RequiresPermissions("system:report:list")*/
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PpDynamicReport ppDynamicReport)
    {
        startPage();
        List<PpDynamicReport> list = ppDynamicReportService.selectPpDynamicReportList(ppDynamicReport);
        return getDataTable(list);
    }

    /**
     * 导出举报动态列表
     */
    @RequiresPermissions("system:report:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PpDynamicReport ppDynamicReport)
    {
        List<PpDynamicReport> list = ppDynamicReportService.selectPpDynamicReportList(ppDynamicReport);
        ExcelUtil<PpDynamicReport> util = new ExcelUtil<PpDynamicReport>(PpDynamicReport.class);
        return util.exportExcel(list, "report");
    }

    /**
     * 新增举报动态
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存举报动态
     */
    @RequiresPermissions("system:report:add")
    @Log(title = "举报动态", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PpDynamicReport ppDynamicReport)
    {
        return toAjax(ppDynamicReportService.insertPpDynamicReport(ppDynamicReport));
    }

    /**
     * 修改举报动态
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        PpDynamicReport ppDynamicReport = ppDynamicReportService.selectPpDynamicReportById(id);
        mmap.put("ppDynamicReport", ppDynamicReport);
        return prefix + "/edit";
    }

    /**
     * 修改保存举报动态
     */
    @RequiresPermissions("system:report:edit")
    @Log(title = "举报动态", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PpDynamicReport ppDynamicReport)
    {
        return toAjax(ppDynamicReportService.updatePpDynamicReport(ppDynamicReport));
    }

    /**
     * 删除举报动态
     */
    @RequiresPermissions("system:report:remove")
    @Log(title = "举报动态", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ppDynamicReportService.deletePpDynamicReportByIds(ids));
    }
}
